package com.zk.hql.entity;

import com.zk.hql.configuration.LogDescribe;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户表表结构
 *
 * @author yuhao
 * @author coolBoy
 */
@Entity
@Table(name = "rp_sys_user")
@LogDescribe(description = "用户", operate = "用户管理")
@Data
public class SysUserEntity implements Serializable {

	private static final long serialVersionUID = 1688315089591200247L;

	/** 主键 */
	@Id
	@GeneratedValue(generator = "generator")
	@GenericGenerator(name = "generator", strategy = "uuid")
	@Column(length = 32)
	private String id;

	/** 用户名 */
	@LogDescribe(description = "用户名")
	@Column(length = 60)
	private String username;

	/** 姓名 */
	private String name;

	/** 登陆密码 */
	@LogDescribe(description = "密码")
	@Column(length = 64)
	private String password;

	/** 说明 */
	@LogDescribe(description = "用户描述")
	@Column(length = 500)
	private String description;

	/** 最后一次登录时间 */
	@LogDescribe(description = "最后登录时间")
	private LocalDateTime lastlogintime;

	/** 登陆ip */
	@Column(length = 32)
	private String ip;

	/** 最后一次更新时间 */
	private LocalDateTime lastUpdateTime;

	/** 最后一次更新人 */
	@Column(length = 50)
	private String lastUpdateUser;

	/** 用户邮箱 */
	private String email;

	/** 用户职位 */
	@Column(name = "rank_")
	private String rank;

	/** 用户类型 */
	@Column(name = "type_")
	private Integer type;

	/** 所在组织 */
	@ManyToOne
	@JoinColumn(name = "org")
	private OrgnazitionEntity org;

	/** 用户状态 */
	private Boolean removed;

	/** 到期日期 */
	@Column(name = "expire_")
	private LocalDate expire;

	/** 系统角色 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rp_sys_user_role", joinColumns = {
			@JoinColumn(name = "user_id", nullable = false, updatable = false) }, inverseJoinColumns = {
					@JoinColumn(name = "role_id", nullable = false, updatable = false) })
	private List<SysRoleEntity> roles;

	/** 系统角色 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rp_sys_user_datrole", joinColumns = {
			@JoinColumn(name = "user_id", nullable = false, updatable = false) }, inverseJoinColumns = {
					@JoinColumn(name = "data_role_id", nullable = false, updatable = false) })
	private List<DataRolesEntity> dataRoles;

	/** 数据范围,可以看到的子组织机构的ID ,多个ID用逗号隔开 */
	private String datas;

	/** 密码失败次数 */
	private int pwdErrTimes;

	private LocalDateTime createTime;

}
